var paytype=0;
var rentorderid="";
$(document).ready(function(){
	PageOnloadP();
	choosePayT();
	payM();
	checkS();
	WantOrderAllInfo();
	GotoRepay();
});
//初始化参数
function PageOnloadP(){
	rentorderid = $("div.rentpay_orderinfo>div:eq(0)").text();
	console.log("rentorderid="+rentorderid);
}
//选择付款方式绑定事件
function choosePayT(){
	$("div.rentpay_info_down_down_weixin").click(function(){
		$("img.rentpay_info_down_down_weixin_twoposi").removeClass("hidden");
		$("img.rentpay_info_down_down_zhifubao_twoposi").addClass("hidden");
		$("div.rentpay_info_down_down_weixin").addClass("errorb");
		$("div.rentpay_info_down_down_zhifubao").removeClass("errorb");
		paytype=0;//paytype==0为微信支付
	});
	$("div.rentpay_info_down_down_zhifubao").click(function(){
		$("img.rentpay_info_down_down_zhifubao_twoposi").removeClass("hidden");
		$("img.rentpay_info_down_down_weixin_twoposi").addClass("hidden");
		$("div.rentpay_info_down_down_weixin").removeClass("errorb");
		$("div.rentpay_info_down_down_zhifubao").addClass("errorb");//不知道为何变色未启动
		paytype=1;//paytype==1为支付宝支付
	});
}
//付款跳转绑定
function payM(){
	$("input#paynow").click(function(){
		
		if(paytype==0){
			$('div#myModal').modal("show")
			window.open(basePath+"/rentweixinpay");
			console.log("微信付款");
		};
		if(paytype==1){
			$('div#myModal').modal("show")
			window.open(basePath+"/pay/alipay/alipay");
			console.log("支付宝付款");
		}
	});	
}
//支付成功按钮绑定判定事件
function checkS(){
	$("button.btn-default:eq(0)").click(function(){
		wantS();
		console.log("click");
	});
}
//判定是否支付成功
function wantS(){
		$.ajax({	
			dataType : "json",
			type : "post",
			url : basePath+"/car/orderstate",
			data : {
				orderid:rentorderid
			},
			
			contentType : "application/x-www-form-urlencoded;charset=utf-8",
			success : function(data) {
				if(data.data.state=="success"){
					$("div#myModal").modal("hide");
					$("div#myModal1").modal("show");
				}else{
					$("div#myModal").modal("hide");
					$("div#myModal2").modal("show");
				}		
			},
			error : function() {
				console.log("访问失败");
			},
			complete : function() {
				
			},
		});
}
//请求订单基本信息
function WantOrderAllInfo(){
	$.ajax({	
		dataType : "json",
		type : "post",
		url : basePath+"/car/payinfo",
		data : {
			id:rentorderid	
		},
		
		contentType : "application/x-www-form-urlencoded;charset=utf-8",
		success : function(data) {
			var proinfo = data.data.ordername;
			var pronum = data.data.ordernum;
			var picture = data.data.picture;
			var carname = data.data.carname;
			var price = data.data.price;
			var name = data.data.name;
			var phone = data.data.phone;
			var email = data.data.email;
			$("div.rentpay_info_top_info_center_two").text(proinfo);
			$("div.rentpay_info_top_info_down_two").text(pronum);
			$("img.rentpay_info_center_up_one_posi").attr("src",picture);
			$("div.rentpay_info_center_up_two_title").text(carname);
			$("div.rentpay_info_top_price_three").text(price);
			$("div.rentpay_info_center_down_item_two:eq(0)").text(name);
			$("div.rentpay_info_center_down_item_two:eq(1)").text(phone);
			$("div.rentpay_info_center_down_item_two:eq(2)").text(email);
			
		},
		error : function() {
			console.log("访问失败");
		},
		complete : function() {
			layer.close(LoadingIcon);
		},
	});
}
//跳转订单支付详情页面
var GotoRepay = function(){
	var url = basePath+"/rentrepay";
	url = encodeURI(url);
	url = encodeURI(url);
	//重点步骤，转码2次，实现传参不出中文乱码或问号
	
	$("button#CheckOrderTwo").click(function(){
		window.location.href = (url);
	});
	$("button#CheckOrderOne").click(function(){
		window.location.href = (url);
	});
	$("button.btn-default:eq(2)").click(function(){
		window.location.href = (url);
	});
	
}